﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;

namespace SpiderServer
{
	public class EventLogs
	{
		private static EventLog s_eventLog;

		static EventLogs()
		{
			string source = "采集服务";
			try
			{
				if (!EventLog.SourceExists(source))
				{
					EventLog.CreateEventSource(source, source);
				}
				s_eventLog = new EventLog();
				s_eventLog.Source = source;
				s_eventLog.Log = source;
			}
			catch
			{
			}
		}

		public static void Error(Exception ex)
		{
			Error(ex.ToString());
		}

		public static void Error(string message)
		{
			Write(message, EventLogEntryType.Error);
		}

		public static void Warning(string message)
		{
			Write(message, EventLogEntryType.Warning);
		}

		public static void Info(string message)
		{
			Write(message, EventLogEntryType.Information);
		}

		private static void Write(string message, EventLogEntryType type)
		{
			try
			{
				s_eventLog.WriteEntry(message, type);
			}
			catch
			{

			}
		}
	}

}
